/*
 * Copyright (c) 2011 Anthony Vandikas
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 
 * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 
 * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 
 * is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include "stdafx.h"
#include "SettingsWidget.h"

#include "AbstractInventory.h"
#include "AbstractHistory.h"
#include "AbstractStudentList.h"
#include "InventoryWidget.h"
#include "StudentWidget.h"
#include "PrintWidget.h"

SettingsWidget::SettingsWidget(AbstractInventory &inventory, AbstractHistory &history, AbstractStudentList &studentList)
	: inventoryWidget(new InventoryWidget(inventory)),
	studentWidget(new StudentWidget(history, studentList)),
	printWidget(new PrintWidget(history))
{
	ui.setupUi(this);
	ui.homeButton->setVisible(false);

	ui.inventoryPage->layout()->addWidget(inventoryWidget);
	ui.studentsPage->layout()->addWidget(studentWidget);
	ui.printingPage->layout()->addWidget(printWidget);
}

SettingsWidget::~SettingsWidget()
{
	delete inventoryWidget;
	delete studentWidget;
	delete printWidget;
}

void SettingsWidget::setPage(int index) 
{ 
	// Home button should be visible on every page except the home page (page 0).
	ui.homeButton->setVisible(index != 0);
	ui.settingsStack->setCurrentIndex(index); 
}

void SettingsWidget::homeButtonClicked() { setPage(0); }
void SettingsWidget::inventoryButtonClicked() {	setPage(1); }
void SettingsWidget::studentsButtonClicked() {	setPage(2); }
void SettingsWidget::printingButtonClicked() {	setPage(3); }
